#pragma once
#include "Player.h"
#include "Piece.h"
#include "AIRandomPlayer.h"
#include "Game.h"

class AIPlayer :
	public AIRandomPlayer
{
public:
	/*This stucture rappresent a possible move in the game and it's the base piece of our n-ary tree
	*/
	typedef struct Move
	{
		int value;
		std::vector<Piece> m_pieces;
		Piece chosenPiece;
		Piece movedPiece;
		Location location;
		struct Move *parent, *child, *rightBrother, *leftBrother;
	} Move;

	AIPlayer(int level);
	Piece *choosePiece(sf::RenderWindow & window, std::vector<Piece> &m_pieces);
	void play(sf::RenderWindow & window, Piece *piece, std::vector<Piece> &m_pieces);
	static int evalutateState(std::vector<Piece> & pieces);
	static const int INFINITY = 2000;
	static const int MINUS_INFINITY = -2000;
	static const int LEVEL_WIDTH = 16;
private:
	static int numberCommonTraits(Piece first, Piece second, Piece third, Piece fourth);
	static Piece getPieceInPosition(std::vector<Piece> & pieces, Location location);
	static Location chooseALocation(std::vector<Piece> &m_pieces);
	static Piece chooseAPiece(std::vector<Piece> &m_pieces);

	//MinMax AplhaBeta
	static AIPlayer::Move alphaBetaSearch(std::vector<Piece> m_pieces, int level, Move *currentMoveChosen);
	static int maxValue(AIPlayer::Move *move, int alphaValue, int betaValue, int level);
	static int minValue(AIPlayer::Move *move, int alphaValue, int betaValue, int level);
	static bool cutOffTest(AIPlayer::Move *move, int level);
	static int maX(int x, int y) { return (x >= y) ? x : y;};
	static int miN(int x, int y) { return (x <= y) ? x : y;};
	AIPlayer::Move *currentMoveChosen;
	int level;
};

